package com.example.mystore.controller;

import com.example.mystore.model.Address;
import com.example.mystore.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/addresses")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @GetMapping("/user/{userId}")
    public List<Address> getAddressesByUserId(@PathVariable Integer userId) {
        return addressService.getAddressesByUserId(userId);
    }

    @GetMapping("list")
    public ResponseEntity<List<Address>> list(Integer id) {
        return ResponseEntity.ok(addressService.list(id));
    }

    @GetMapping("get")
    public ResponseEntity<Address> get(Integer id) {
        return ResponseEntity.ok(addressService.get(id));
    }

    @PostMapping("save")
    public ResponseEntity<Integer> save(@RequestBody Address address) {
        return ResponseEntity.ok(addressService.save(address));
    }

    @PutMapping("update")
    public ResponseEntity<Integer> update(@RequestBody Address address) {
        return ResponseEntity.ok(addressService.update(address));
    }

    @DeleteMapping("delete")
    public ResponseEntity<Integer> delete(Integer id) {
        return ResponseEntity.ok(addressService.delete(id));
    }

    @PostMapping("setDefault")
    public ResponseEntity<Integer> setDefault(Integer id) {
        return ResponseEntity.ok(addressService.setDefault(id));
    }
}